//
//  joinQuestTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/9.
//

#import "joinQuestTableViewCell.h"
@interface joinQuestTableViewCell ()

@property (nonatomic ,strong) UILabel * taskName;
@property (nonatomic ,strong) UILabel * statusName;
@property (nonatomic ,strong) UILabel * pondName;
@property (nonatomic ,strong) UILabel * createTime;
@property (nonatomic ,strong) UILabel * userName;
@property (nonatomic ,strong) UILabel * handover;
@property (nonatomic ,strong) UIButton * qrbtn;

@end
@implementation joinQuestTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    
    UIView * backview = [UIView new];
    [self.contentView addSubview:backview];
    backview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(5) andView:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.bottom.offset(kwt(-10));
    }];

    
    UILabel * statusName = [DTKTool labelWithText:@"--" andFont:kCFont(15) andTextColor:UIColor.whiteColor];
    self.statusName= statusName;
    statusName.textAlignment = NSTextAlignmentCenter;
    [backview addSubview:statusName];
    [statusName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-12));
        make.width.offset(kwt(58));
        make.height.offset(kwt(25));
        make.top.offset(kwt(12));
    }];
    
    
    UILabel * taskName = [DTKTool labelWithText:@"--" andFont:kCFont(18) andTextColor:KcolorHex(@"#0967FF")];
    self.taskName= taskName;
    [backview addSubview:taskName];
    [taskName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.right.equalTo(statusName.mas_left).offset(kwt(-10));
        make.top.offset(kwt(15));
    }];
    
    UILabel * pondName = [DTKTool labelWithText:@"--" andFont:kCFont(16) andTextColor:KcolorHex(@"#222222")];
    self.pondName= pondName;
//    pondName.numberOfLines = 0;
    [backview addSubview:pondName];
    [pondName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-12));
        make.left.offset(kwt(12));
        make.top.offset(kwt(46));
        make.height.offset(kwt(16));
    }];
    
    
    UILabel * templab = [DTKTool labelWithText:@"申请时间：" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    [backview addSubview:templab];
    [templab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.top.equalTo(pondName.mas_bottom).offset(kwt(12));
    }];
    
    UILabel * createTime = [DTKTool labelWithText:@"--" andFont:kFont(15) andTextColor:KcolorHex(@"#222222")];
    self.createTime= createTime;
    [backview addSubview:createTime];
    [createTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(templab.mas_right);
        make.centerY.equalTo(templab);
    }];
    
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#DBDBDB");
    [backview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(templab.mas_bottom).offset(kwt(14));
        make.right.offset(kwt(-12));
        make.left.offset(kwt(12));
        make.height.offset(0.5);
    }];
    
    UIView * sxlab = [UIView new];
    sxlab.backgroundColor = KcolorHex(@"#CECECE");
    [backview addSubview:sxlab];
    [sxlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(line.mas_top).offset(kwt(25));
        make.width.offset(kwt(1));
        make.left.offset(kwt(15));
        make.height.offset(kwt(22));
    }];
   
    UIView * zjrview = [UIView new];
    zjrview.backgroundColor = KcolorHex(@"#FF8800");
    [DTKTool YJ:kwt(4) andView:zjrview];
    [backview addSubview:zjrview];
    [zjrview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(line.mas_top).offset(kwt(18));
        make.height.width.offset(kwt(8));
        make.centerX.equalTo(sxlab);
    }];
    
    UILabel * templab1 = [DTKTool labelWithText:@"转交人：" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    [backview addSubview:templab1];
    [templab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(27));
        make.centerY.equalTo(zjrview);
    }];
    
    UILabel * userName = [DTKTool labelWithText:@"--" andFont:kFont(15) andTextColor:KcolorHex(@"#222222")];
    self.userName= userName;
    [backview addSubview:userName];
    [userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(templab1.mas_right);
        make.centerY.equalTo(templab1);
    }];
    
    UIView * jsrview = [UIView new];
    jsrview.backgroundColor = KcolorHex(@"#02BD4B");
    [DTKTool YJ:kwt(4) andView:jsrview];
    [backview addSubview:jsrview];
    [jsrview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(zjrview.mas_bottom).offset(kwt(21));
        make.height.width.offset(kwt(8));
        make.centerX.equalTo(sxlab);
    }];
    
    UILabel * templab2 = [DTKTool labelWithText:@"接收人：" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    [backview addSubview:templab2];
    [templab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(27));
        make.centerY.equalTo(jsrview);
    }];
    
    UILabel * handover = [DTKTool labelWithText:@"--" andFont:kFont(15) andTextColor:KcolorHex(@"#222222")];
    self.handover= handover;
    [backview addSubview:handover];
    [handover mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(templab2.mas_right);
        make.centerY.equalTo(templab2);
    }];
    
    
    UIButton * qrbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qrbtn.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(351), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#2892FE") endColor:KcolorHex(@"#0366FE")];
    [qrbtn setTitle:@"确认接收" forState:UIControlStateNormal];
    [qrbtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    qrbtn.titleLabel.font = kCFont(17);
    [DTKTool YJ:kwt(5) andView:qrbtn];
    self.qrbtn = qrbtn;
    [qrbtn addTarget:self action:@selector(rightbtnclick) forControlEvents:UIControlEventTouchUpInside];
    [backview addSubview:qrbtn];
    [qrbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(37));
        make.width.offset(kwt(351));
        make.centerX.offset(0);
        make.top.equalTo(handover.mas_bottom).offset(kwt(15));
    }];
  
    
    
}
- (void)rightbtnclick{
    if(self.openJSBlock){
        self.openJSBlock(self.model);
    }
}

- (void)setModel:(joinQuestListModel *)model {
    _model = model;
    if([model.executeTime componentsSeparatedByString:@"-"].firstObject.length == 4){
        model.executeTime = [model.executeTime stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@-",[model.executeTime componentsSeparatedByString:@"-"].firstObject] withString:@""];
    }
    self.taskName.text = [NSString stringWithFormat:@"%@ %@",model.executeTime,model.taskName];
    self.statusName.text = model.statusName;
    self.statusName.textColor = KcolorHex(model.statusColor);
    [DTKTool YJBK:kwt(4) andView:self.statusName andWidth:1 andColor:KcolorHex(model.statusColor)];
//    self.pondName.text = [NSString stringWithFormat:@"%@ %@",model.pondTissue,model.pondName];
//    [self.pondName mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.height.offset(model.pondNameH);
//    }];
//    self.pondName.text = model.tissueListStr;
    NSArray * pondStrArray = [model.tissueListStr componentsSeparatedByString:@"\n"];
//    if (pondStrArray.count > 1){
//        self.pondName.text = [NSString stringWithFormat:@"%@...",pondStrArray.firstObject];
//
//    } else {
        self.pondName.text = pondStrArray.firstObject;

//    }
//        [self.pondName mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.height.offset(model.tissueListStrH);
//        }];
    self.createTime.text = model.createTime;
    self.userName.text = model.userName;
    self.handover.text = model.handover;
    self.qrbtn.hidden = !model.button;
    
}

@end
